home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABUControls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-23  |  8.1 KB  |  374 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUControls.c
  15.  
  16. NAME
  17.     ABUControls.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox Controls stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                netromancr@aol.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     14 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  38.                             release and the associated Universal Headers from Apple:
  39.                             most methods that returned references now have "Ref" at
  40.                             the end of their methods names to prevent possible collisions
  41.                             with datatypes and classes of the same name (older versions
  42.                             of the compiler didn't have a problem with this).
  43.  
  44. */
  45.  
  46. /*===========================================================================*/
  47.  
  48. /*======= Segmentation directives ========*/
  49.  
  50. #ifdef USE_MANUAL_SEGMENTATION
  51. #pragma segment ty
  52. #endif
  53.  
  54. /*============ Header files ==============*/
  55.     
  56. #include     "ABUControls.h"
  57.  
  58. /*=============== Globals ================*/
  59.  
  60. /*================ CODE ==================*/
  61.  
  62.  
  63. /*=============================== ABUControls::ABUControls ================================*/
  64. ABUControls::ABUControls(void)
  65. {
  66.     cList = NULL;
  67.     cNumber = 0;
  68. }    // end ABUControls
  69.  
  70.  
  71. /*=============================== ABUControls::~ABUControls ================================*/
  72. ABUControls::~ABUControls(void)
  73. {
  74.     if (cList)
  75.     {
  76.         DisposPtr((Ptr)cList);
  77.         cList = NULL;
  78.     }
  79.     cNumber = 0;
  80.     
  81. }    // end ~ABUControls
  82.  
  83.  
  84.  
  85.  
  86.  
  87. /*=============================== ABUControls::FlashControl ===============================*/
  88. //
  89. //    FlashControl will simulate a user-click on the
  90. //    control specified. Specifically, it simulates the visual 
  91. //    aspects of a user clicking or selecting a control...useful when
  92. //    intercepting events in an event filter proc.
  93. //
  94. //    based upon DialogBits by CK Haun, Apple Dev Tech Suppt.
  95. //
  96. //
  97. //    is called by:
  98. //        DoEvent
  99. //
  100. Boolean    ABUControls::FlashControl (ControlHandle ctrl)
  101. {
  102.     Boolean        active = false;
  103.     long        timer;
  104.     const long    duration = 8;
  105.     
  106.     if (ctrl) 
  107.     {
  108.         active = IsControlActive(ctrl);
  109.         if (active)
  110.         {
  111.             HiliteControl(ctrl, true);
  112.             Delay(duration, &timer);                //    wait about 8 ticks so they can see it
  113.             HiliteControl(ctrl, false);
  114.         }
  115.     }    //    end if block
  116.         
  117.     return active;
  118. }    //    end of function FlashControl()
  119.  
  120.  
  121.  
  122.  
  123. /*=============================== ABUControls::IsControlActive ===============================*/
  124. //
  125. //    IsControlActive will return a value of either true or
  126. //    false, indicative of whether the given control is indeed
  127. //    active or not.
  128. //
  129. //
  130. //    is called by:
  131. Boolean    ABUControls::IsControlActive (ControlHandle ctrl)
  132. {
  133.     if (ctrl)
  134.         if ((*ctrl)->contrlHilite == kABdeactivateControl)
  135.             return false;
  136.         else
  137.             return true;
  138.     else
  139.         return false;
  140. } // end IsControlActive()
  141.  
  142.  
  143.  
  144.  
  145.  
  146. /*=============================== ABUControls::CheckControl ===============================*/
  147. //
  148. //    CheckControl will set/unset a control.
  149. //
  150. //
  151. //    is called by:
  152. OSErr    ABUControls::CheckControl (ControlHandle ctrl, Boolean setCondition)
  153. {
  154.     if (ctrl)
  155.     {
  156.         HiliteControl (ctrl, (setCondition ? kABactivateControl : kABdeactivateControl));
  157.         return noErr;
  158.     } else {
  159.         return paramErr;
  160.     } // end if else block
  161.  
  162. } // end CheckControl()
  163.  
  164.  
  165.  
  166.  
  167.  
  168. /*=============================== ABUControls::CheckAllControls ===============================*/
  169. //
  170. //    CheckAllControls will set/unset all the controls in a window.
  171. //
  172. //
  173. //    is called by:
  174. OSErr    ABUControls::CheckAllControls (WindowPtr theWindow, Boolean setCondition)
  175. {
  176.     ControlHandle    ctrlHandle = NULL;
  177.     OSErr            error = noErr;
  178.     
  179.     //    begin here...
  180.     
  181.     if (theWindow)
  182.     {
  183.         //    nothing, so check to see if we can walk the
  184.         //    window's control list and find the nth control
  185.         ctrlHandle = ((WindowPeek)theWindow)->controlList;
  186.     
  187.         while (ctrlHandle)
  188.         {
  189.             error = CheckControl (ctrlHandle, setCondition);
  190.             ctrlHandle = (*ctrlHandle)->nextControl;
  191.         } // end while loop
  192.     } else {
  193.         error = paramErr;
  194.     } // end if else block
  195.  
  196.     return error;
  197. } // end CheckAllControls()
  198.  
  199.  
  200.  
  201.  
  202.  
  203. /*=============================== ABUControls::GetControlHandle ===============================*/
  204. //
  205. //    GetControlHandle will return a handle to a given control item
  206. //    in the given dialog box. If the item is _not_ a control then
  207. //    a kABbadControlHandle is returned.
  208. //
  209. //    based upon SnatchHandle() by CK Haun, Apple Dev Tech Suppt.
  210. //
  211. //    Handy for setting checkboxes and radio buttons
  212. //
  213. //
  214. //    is called by:
  215. //
  216. ControlHandle    ABUControls::GetControlHandle (GrafPtr window, short theGetItem)
  217. {
  218.     short            index = 1;
  219.     short             itemType;
  220.     Rect             itemRect;
  221.     Handle            itemHandle = NULL;
  222.     ControlHandle    ctrlHandle = NULL;
  223.     
  224.     if (!(window && (theGetItem > 0))) 
  225.     {
  226.         return NULL;
  227.     } // end if block
  228.     
  229.     GetDItem(window, theGetItem, &itemType, &itemHandle, &itemRect);
  230.     
  231.     if (itemHandle)
  232.     {
  233.         //    GetDItem returned something...
  234.         
  235.         ctrlHandle = (ControlHandle)itemHandle;
  236.         if (!(itemType & ctrlItem))
  237.         {
  238.             ctrlHandle = NULL;
  239.         } // end if else block
  240.     } else {
  241.         //    nothing, so check to see if we can walk the
  242.         //    window's control list and find the nth control
  243.         ctrlHandle = ((WindowPeek)window)->controlList;
  244.     
  245.         while (ctrlHandle && (index != theGetItem))
  246.         {
  247.             ctrlHandle = (*ctrlHandle)->nextControl;
  248.             ++index;
  249.         } // end while loop
  250.         
  251.         if (index != theGetItem)
  252.             ctrlHandle = NULL;
  253.     
  254.     } // end if block
  255.     
  256.     return ctrlHandle;
  257.     
  258. }    //    end of function GetControlHandle
  259.  
  260.  
  261.  
  262.  
  263. /*=============================== ABUControls::CountControls ===============================*/
  264. //
  265. //    CountControls will count the number of control items in the given window.
  266. //
  267. short    ABUControls::CountControls (WindowPtr window)
  268. {
  269.     short            number = 0;
  270.     ControlHandle    ctrl = NULL;
  271.     
  272.     //    begin here...
  273.     
  274.     if (!window)
  275.         return number;
  276.         
  277.     ctrl = ((WindowPeek)window)->controlList;
  278.     while (ctrl)
  279.     {
  280.         ++number;
  281.         ctrl = (*ctrl)->nextControl;
  282.     } // end while loop
  283.     
  284.     return number;
  285. } // end CountControls
  286.  
  287.  
  288.  
  289.  
  290.  
  291. /*=============================== ABUControls::SaveControlStates ===============================*/
  292. //
  293. //    SaveControlStates will save the states of all controls in the given
  294. //    window, for restoration later.
  295. //
  296. OSErr    ABUControls::SaveControlStates (WindowPtr window)
  297. {
  298.     OSErr            error = noErr;
  299.     ControlHandle    ctrl = NULL;
  300.     short            index;
  301.     
  302.     //    begin here...
  303.     
  304.     if (!window)
  305.         return paramErr;
  306.  
  307.     if (cList)
  308.     {
  309.         DisposPtr((Ptr)cList);
  310.         cList = NULL;
  311.         cNumber = 0;
  312.     } // end if block
  313.     
  314.     cNumber = CountControls(window);
  315.     
  316.     if (!cNumber)
  317.     {
  318.         return paramErr;
  319.     } else {
  320.         cList = (ABControlListPtr)NewPtrClear (cNumber * sizeof(ABControlList));
  321.         error = MemError();
  322.     } // end if else block
  323.     
  324.     if (error)
  325.         return error;
  326.         
  327.     ctrl = ((WindowPeek)window)->controlList;
  328.     index = 0;
  329.     while (ctrl)
  330.     {
  331.         cList[index].handle = ctrl;
  332.         cList[index].state = (*ctrl)->contrlHilite;
  333.         ++index;
  334.         ctrl = (*ctrl)->nextControl;
  335.     } // end while loop
  336.     
  337.     return error;
  338. } // end SaveControlStates
  339.  
  340.  
  341.  
  342.  
  343.  
  344. /*=============================== ABUControls::RestoreControlStates ===============================*/
  345. //
  346. //    RestoreControlStates will save the states of all controls in the given
  347. //    window, for restoration later.
  348. //
  349. OSErr    ABUControls::RestoreControlStates (WindowPtr window)
  350. {
  351.     OSErr            error = noErr;
  352.     short            index;
  353.     
  354.     //    begin here...
  355.     
  356.     if (!(window && cList && cNumber))
  357.         return paramErr;
  358.  
  359.     for (index = 0; index < cNumber; ++index)
  360.     {
  361.         HiliteControl(cList[index].handle, cList[index].state);
  362.     } // end for loop
  363.     
  364.     return error;
  365. } // end RestoreControlStates
  366.  
  367.  
  368.  
  369.  
  370. //    end of file.
  371.  
  372.  
  373.  
  374.